package com.juzipi.thread.test.pool;

import java.util.concurrent.*;

/**
 * @Author juzipi
 * @Date 2021/6/18 8:12
 * @Info
 */
public class ThreadPool {
    public static void main(String[] args) {
        //线程池
        ExecutorService executorService = Executors.newFixedThreadPool(200);
        executorService.execute(new MyThread());
        executorService.execute(new MyThread());
        executorService.execute(new MyThread());
        executorService.execute(new MyThread());
        executorService.execute(new MyThread());
        executorService.execute(new MyThread());

        executorService.shutdown();

        FutureTask<String> futureTask = new FutureTask<>(new MyThread2());
        new Thread(futureTask).start();
        try {
            String s = futureTask.get();
            System.out.println(s);
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }

    }

}

class MyThread implements Runnable {
    @Override
    public void run() {

        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName());
        }

    }
}

//继承Thread
class MyThread1 extends Thread{

    @Override
    public void run() {
        System.out.println(this.getName());
    }

}

class MyThread2 implements Callable<String>{
    @Override
    public String call() throws Exception {
        return "你好";
    }
}